package sorttest;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;

public class Compare implements Comparable<Compare>{

    public static void main(String[] args) {
        new SimpleDateFormat("").format(new Date());
        Compare a = new Compare(1, 2);
        Compare b = new Compare(1, 1);
       Compare[] com = {a,b};
        Arrays.sort(com);
        for (Compare compare : com) {
            System.out.println(compare);
        }
    }
    int first ,second;

    public Compare(int first, int second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public String toString() {
        return "Compare{" +
                "first=" + first +
                ", second=" + second +
                '}';
    }

    @Override
    public int compareTo(Compare o) {
        if (first==o.first){
            return second-o.second;
        }
        return first-o.first;
    }
}
